﻿using System.Collections.Generic;
using Gp.Scripts.Core;
using Gp.Scripts.Data;
using Gp.Scripts.Data.Skills;
using Gp.Scripts.Equip;

namespace Gp.Scripts.Core {
    
    /// <summary>
    /// 攻击发动的规则参数
    /// </summary>
    public class AttackActionRequest : IActionRequest {
        public BaseUnit Source { get; }
        public BaseUnit Target { get; }


        public int Damage { get; set; }

        public bool IsHit { get; set; } = true;

        
        public float DefencePercent { get; set; }


        public List<SkillTags> Tags { get; }


        public DamageType DamageType { get; } = DamageType.Physic;


        public SkillEntity Skill { get; }


        public readonly List<BaseBuff> BuffConsume = new();

        
        public bool PlayMeleeCounterAttack { get; set; }

        
        

        /// <param name="source">攻击发起者</param>
        /// <param name="target">攻击目标</param>
        /// <param name="skill"></param>
        /// <param name="entity">武器实体</param>
        /// <param name="defencePercent">发生了格挡</param>
        public AttackActionRequest(BaseUnit source, BaseUnit target, SkillEntity skill,
            WeaponEntity entity, float defencePercent) {
            // var weapon = entity.Equip;

            Skill = skill;


            // 造成伤害为 力量属性 + 武器伤害
            Damage = source.ComStat[StatField.Strength] + source.ComEquip.CurWeapon.GetDamage();
            DefencePercent = defencePercent;

            Source = source;
            Target = target;
            Tags = new List<SkillTags>();
        }
        
        
        
        public AttackActionRequest(BaseUnit source, BaseUnit target, SkillEntity skill,
            WeaponEntity entity, AttackPreReaction args) {
            var weapon = entity.Config;


            Skill = skill;

            // 造成伤害为 
            Damage = entity.GetDamage(target);
            DefencePercent = args.DefencePercent;
            PlayMeleeCounterAttack = args.MeleeCounterAttack;

            Source = source;
            Target = target;
            Tags = new List<SkillTags>(entity.SkillTag());
        }

        public AttackActionRequest(BaseUnit source, BaseUnit target, SkillEntity magicSkill, int damage) {
            Source = source;
            Target = target;
            // Tags = magicSkill.EntityConfig.skillTags;
            Damage = damage;

            Skill = magicSkill;
        }


        public void BonusDamage(ModifierValue bonus) {
            Damage = bonus.ResultInt(Damage);
        }
    }
}